﻿(function (module) {

	module.controllers.add({
		name: 'contacts',
		actions: {
			index: function () {
				module.modelRouters.fetch('contacts', function (m) {
					module.view('index', { contacts: m });
				});
			},
			edit: function (id) {
				if (!id)
					module.view('edit');
				else {
					module.modelRouters.fetch('contact', function (m) {
						module.view('edit', { contact: m });
					},
					{ id: id });
				}
			}
		}
	});

	module.views.add({
		name: 'index',
		url: '/jmvc-modules/contacts/views/index.html',
		templateId: '#contacts-views-index',
		el: '#page-content'
	});

	module.views.add({
		name: 'edit',
		url: '/jmvc-modules/contacts/views/index.html',
		templateId: '#contacts-views-edit',
		el: '#page-content'
	});


	module.modelRouters.add({
		name: 'contacts',
		url: '/contacts/'
	});

	module.modelRouters.add({
		name: 'contact',
		url: '/contacts/index/:id'
	});

	module.onload = function () {
		this.action('contacts');
	}


})(jmvc.module('contacts'));


